#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
stack<pair<char,LL>>s;
multiset<LL>s1;
char str[maxn];
int main(void){
   ////cin.tie(0);std::ios::sync_with_stdio(false);
   cin>>(str+1);LL n=strlen(str+1);
   for(LL i=1;i<=n;i++){
       if(s.empty()&&str[i]=='('){
          s.push({'(',i});
       }
       else if(s.empty()&&str[i]==')'){
          s1.insert(i);
       }
       else if(!s.empty()){
          if(str[i]==')'&&s.top().first=='('){
             s.pop();
          }
          else if(str[i]=='('){
             s.push({'(',i});
          }
       }
   }
   while(!s.empty()){
         s1.insert(s.top().second);s.pop();
   }
   for(auto i:s1){
       cout<<i<<" ";
   }
   cout<<"\n";
   LL m;cin>>m;
   multiset<LL>:: iterator it;
   while(m--){
       LL l,r;cin>>l>>r;
       it=s1.lower_bound(l);
       if((*it)<=r){
          cout<<0<<"\n";
       }
       else{
          cout<<r-l+1<<"\n";
       }
   }
   return 0;
}
